package net.zjitc.dao;

import net.zjitc.Utils.C3P0Utils;
import net.zjitc.domain.User;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

/**
 * Created by Administrator on 2017/9/27.
 */

/**
 * 定义一个dao，用来取数据库的数据，直接和数据库交互 ，
 * 取数据使用数据库连接池及DBUtils
 */
public class UserDao {

    public User findByUsernameAndPassword(String username, String password) throws SQLException {
        QueryRunner runner = new QueryRunner(C3P0Utils.getDataSource());
        String sql = "select * from user where username = ? and password = ?";
        User user = (User) runner.query(sql,new BeanHandler(User.class),username,password);
        return user;
    }
}
